<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>join</title>
</head>

<body>
    <script>
        const join = (arr, separator = ',', end = separator) => arr.reduce((acc, val, i) => i == arr.length - 2 ? acc + val + end : i === arr.length - 1 ? acc + val : acc + val + separator, '');
        document.write(`join(['pen', 'pineapple', 'apple', 'pen'], ',', '&')的结果是:${join(['pen', 'pineapple', 'apple', 'pen'], ',', '&')}`)
    </script>
</body>

</html>